<%--
  Created by IntelliJ IDEA.
  User: zhao
  Date: 6/11/2022
  Time: 15:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>
<head>
    <title>基础信息</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css" >
</head>
<body>
<form class="layui-form" action=""  id="saveUserForm" lay-filter="updateUserFormFilter">
    <input type="hidden" name="id" >

    <form class="layui-form" enctype="multipart/form-data" action="" >

        <div class="registerbox-title">用户基础信息</div>
        <div class="layui-form-item">
            <div class="layui-form-item pass" >
                <label class="layui-form-label">用户id</label>
                <div class="layui-input-inline">
                    <input type="text" name="id" autocomplete="off" value="${user.id}" disabled
                           class="layui-input" id="id">
                </div>
            </div>
            <label class="layui-form-label">用户账号</label>
            <div class="layui-input-inline">
                <input type="text" name="username" id="username" lay-verify="required" value="${user.username}" disabled placeholder="请输入账号" autocomplete="off"
                       class="layui-input">
            </div>



        </div>



        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block">
                <input type="text" name="sex" value="${user.sex}" class="layui-input" style="width:190px;" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">角色</label>
            <div class="layui-input-block">
                <input type="text" id="role" name="role" value="" class="layui-input" style="width:190px;" disabled>
            </div>
        </div>

<%--        <div class="layui-inline">--%>
<%--            <label class="layui-form-label">角色</label>--%>
<%--            <div class="layui-input-block">--%>
<%--                <select name="rid"   class="layui-select ridSelect" value="${user.rid}">--%>
<%--                    <option value="">请选择...</option>--%>
<%--                    &lt;%&ndash;                    <option value="1">启用</option>&ndash;%&gt;--%>
<%--                    &lt;%&ndash;                    <option value="2">禁用</option>&ndash;%&gt;--%>
<%--                </select>--%>
<%--            </div>--%>

<%--        </div>--%>


        <%--状态--%>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <c:if test="${user.status=='1'}">
                    <input type="checkbox" id="kaiguan" name="statusswitch" checked  lay-skin="switch" lay-filter="switchStatus" lay-text="启用|禁用" disabled>
                </c:if>

                <c:if test="${user.status=='2'}">
                    <input type="checkbox" id="kaiguan" name="statusswitch"  lay-skin="switch" lay-filter="switchStatus" lay-text="启用|禁用" disabled>
                </c:if>

            </div>
        </div>

        <%--开关   选中的时候 on   未选中的时候 off  一般不用开关传值   on 1  off 2--%>


        <div class="layui-form-item">
            <div class="layui-upload" style="margin-left: 90px">
                <div class="layui-upload-list" style="margin:10px -3px;">

                    <img class="layui-upload-img"
                         width="100px" height="100px" style="border-radius: 50%" id="demo1" src="${user.imgpath}">
                    <p id="demoText"></p>
                </div>
            </div>
        </div>

    </form>
</form>

<script src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
<script src="${pageContext.request.contextPath}/static/jquery-3.6.1.min.js"></script>
<script>

    layui.use(['table','layer','form','jquery','tree'], function() {
        var tree = layui.tree;
        var table = layui.table;
        var layer = layui.layer;
        var form = layui.form;
        var $ = layui.jquery;

        // 监听单元格里面的开关
        form.on('switch(switchStatus)', function(obj){
            //alert(JSON.stringify(obj));
            var status=1;
            if(this.checked){
                status=1
            }else{
                status=2;
            }
            // 修改这条数据的状态即可
            $.ajax({
                type:"post",
                data:{id:obj.value,status:status},
                url:"${pageContext.request.contextPath}/tuser/updUser",
                success:function(d){
                    if(d.code==0){
                        layer.msg("修改成功",{icon:"1"});
                        table.reload('test');
                    }
                }
            })

        });
    });
    $(function (){
        // 获取所有的角色得到信息
        <%--$.ajax({--%>
        <%--    url:"${pageContext.request.contextPath}/tRole/queryRid",--%>
        <%--    dataType:"JSON",--%>
        <%--    success:function (ret) {--%>
        <%--        if(ret.code==0){--%>
        <%--            //<option value="0">写作</option>--%>
        <%--            var htmlStr="<option value=''>--请选择--</option>";--%>
        <%--            for (let i = 0; i < ret.data.length; i++) {--%>
        <%--                htmlStr+="<option value="+ret.data[i].id+">"+ret.data[i].rname+"</option>"--%>
        <%--            }--%>
        <%--            // alert(htmlStr);--%>
        <%--            $(".ridSelect").html(htmlStr);--%>
        <%--            //重新渲染表单--%>

        <%--            layui.use('form',function () {--%>
        <%--                var form=  layui.form;--%>
        <%--                form.render('select');--%>
        <%--            })--%>

        <%--        }--%>

        <%--    },--%>

        <%--});--%>

    });



    $(function (){
            var params={};
            params.rid=${user.rid}
                $.ajax({
                    url:"${pageContext.request.contextPath}/tRole/queryId",
                    type:"post",
                    dataType:"JSON",
                    data:params,//表单里所有数据
                    success:function (ret){

                        $("#role").val(ret.data)
                    }
                })

        },
    )
</script>
</body>
</html>
